package db;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateCallback;

import junit.framework.TestCase;

public class ReccompanyDAOTest extends TestCase {
	ReccompanyDAO reccompanyDao;
	
	protected void setUp() throws Exception {
		ApplicationContext ctx = new FileSystemXmlApplicationContext(
				"D:/workspace/ERP/src/applicationContext.xml");
		reccompanyDao = ReccompanyDAO.getFromApplicationContext(ctx);
	}
	
	public void testSave() {
		
		reccompanyDao.getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				
				Transaction transaction = session.beginTransaction();
				
				Reccompany reccompany = new Reccompany();
				reccompany.setName("test");
				session.save(reccompany);
				
				transaction.commit();
						
				return null;
			}
		});
		
	}

}
